package service;

import java.util.List;
import java.util.Map;

import dao.CategoryDao;
import entity.Category;

public class CategoryService {
	public List<Map<String, Object>> queryAllCategory() throws Exception{
		CategoryDao dao = new CategoryDao();
		
		//查找一级分类
		 List<Map<String, Object>> categoryList = dao.queryAllCategoryByParentId(new Integer(1));
		if (categoryList != null && categoryList.size() > 0) {
			//查找二级分类
			for (int i = 0; i < categoryList.size(); i++) {
				Integer id = (Integer) categoryList.get(i).get("id");
				List<Map<String, Object>> subCategoryList = dao.queryAllCategoryByParentId(id);
				categoryList.get(i).put("subCategoryList", subCategoryList);
			}
		}
		
		return categoryList;
	}
	
	/**
	 * book_list.jsp左栏信息
	 * @return
	 */
	public List<Map<String, Object>> querySubCategoryInfo(Integer parent_id) throws Exception {
		return new CategoryDao().querySubCategoryInfo(parent_id);
	}
	
	/**
	 * book_list.jsp左栏信息
	 */
	public Category queryCategoryById(Integer id) throws Exception{
		return new CategoryDao().queryCategoryById(id);
	}
}
